//
//  ViewController.m
//  14__半塘练习
//
//  Created by 冀永金 on 16/8/2.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "ImageCollectionViewCell.h"
#import "LabalCollectionReusableView.h"
#import "SortCollectionReusableView.h"
@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    UICollectionView *collection = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    layout.itemSize = CGSizeMake((self.view.frame.size.width -15) / 3, (self.view.frame.size.width -15) / 3);
   // layout.sectionInset = UIEdgeInsetsMake(40, 5, 10,5);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 5;
    
    // 头大小
    layout.headerReferenceSize = CGSizeMake(0, 50);
    [self.view addSubview:collection];
    collection.delegate = self;
    collection.dataSource = self;
    [collection registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:@"pool"];
    [collection registerClass:[LabalCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool1"];
    [collection registerClass:[SortCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool2"];
    collection.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f  blue:arc4random() % 256 / 255.0f  alpha:1.0];
    // Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
       return 100;
    
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
  ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f  blue:arc4random() % 256 / 255.0f  alpha:1.0];
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        SortCollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool2" forIndexPath:indexPath];
        return view;
    }
    else {
     LabalCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"pool1" forIndexPath:indexPath];
        header.backgroundColor = [UIColor yellowColor];
                return header;
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 400);
    }else {
        return CGSizeMake(0, 50);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
